<template>
  <div class="public_main">
    <div class="crumbs">
      <el-breadcrumb separator="/" >
        <!-- <el-breadcrumb-item v-if="routeName=='usersug'">{{$t('sidebar.operator')}}</el-breadcrumb-item>
        <el-breadcrumb-item v-if="routeName=='usersug'">{{$t('newcrumbs.crumbsThr')}}</el-breadcrumb-item>
        <el-breadcrumb-item v-else>{{$t('newcrumbs.crumbsOne')}}</el-breadcrumb-item> -->
        <el-breadcrumb-item v-if="$route.path=='/usersugs'">{{$t('sidebar.business')}}</el-breadcrumb-item>
        <el-breadcrumb-item v-else>{{$t('newcrumbs.crumbsOne')}}</el-breadcrumb-item>
        <el-breadcrumb-item>{{$t('userSuggest.crumbsOne')}}</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <!-- ------------ 搜索查询栏开始 -------------- -->
    <search 
			:searchData="searchData" 
			@search="search" 
			@putExcel="putExcel" 
			:searchRight="true"
			:outputRight="$store.state.common.permiss[routeName].includes('export')"
    ></search>
    <!-- ------------ 搜索查询栏结束 -------------- -->


    <!-- ------------ 列表附加功能开始 -------------- -->
    <div class="list_operation" v-if="$store.state.common.permiss[routeName].includes('batch')">
      <el-button v-if="allFlag" type="primary" @click.stop="allDataDispose">+{{$t('userSuggest.all')}}</el-button>
      <el-button v-else type="info" >+{{$t('userSuggest.all')}}</el-button>
    </div>
    <!-- ------------ 列表附加功能结束 -------------- -->

    <!-- ------------ 表单栏开始 -------------- -->
    <div class="table">
      <template>
        <el-table :data="tableData" size="small" stripe style="width: 100%" @selection-change="handleSelectionChange">
          <el-table-column type="selection" :selectable="unSelect" width="55" v-if="routeName=='usersug'">
          </el-table-column>
          <el-table-column align="center" prop="user.phone" :label="$t('public.userPhone')" >
          </el-table-column>
          <el-table-column align="center" prop="content" :label="$t('userSuggest.suggest')" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column align="center" prop="createTime" :label="$t('public.submitDate')" width="86">
          </el-table-column>

          <el-table-column align="center" prop="status" :label="$t('userSuggest.status')" >
            <template slot-scope="scope">
              <span>{{$t($store.getters.sugStatus(scope.row.status))}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="feedbackType" :label="$t('add.no1')" >
            <template slot-scope="scope">
              <span>{{$t($store.getters.sugTypeStatus(scope.row.feedbackType))}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="user.name" :label="$t('userSuggest.sugPerson')" >
          </el-table-column>
          <el-table-column align="center" prop="user.appName" :label="$t('public.appName')" >
          </el-table-column>
          <el-table-column align="center" prop="user.appPackage" :label="$t('public.appPackage')" >
          </el-table-column>
          <el-table-column fixed="right" align="center" prop="operation" :label="$t('public.operation')" min-width="160">
            <template slot-scope="scope">
              <span 
                v-if="$store.state.common.permiss[routeName].includes('view')"
                class="table_opr" 
                @click="sugDetail(scope.row)"
              >
                {{$t('public.no29')}}
              </span>
              <span 
                v-if="$store.state.common.permiss[routeName].includes('reply')&&(scope.row.status==2||scope.row.status==1)"
                style="color:#547ef6;cursor:pointer;margin:0 5px;"
                @click="reply(scope.row)">
              {{$t('userSuggest.replay')}}
              </span>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </div>
    <!-- ------------ 表单栏结束 -------------- -->

    <!-- -------------分页显示栏------------------------ -->
    <el-row type="flex" justify="end">
      <div class="pages" >
        <el-pagination
          @current-change="handleCurrentChange"
          :current-page="pagination.current"
          layout="sizes, prev, pager, next, total,->"
          :page-sizes="pagination.pageSizeOptions"
          :page-size="pagination.pageSize"
          @size-change="handleSizeChange"
          :total="pagination.total">
        </el-pagination>
      </div>
    </el-row>

    <!-- ------------------ 点击查看详情弹窗开始 -------------------- -->
    <el-dialog :title="$t('userSuggest.title1')" :visible.sync="detailFlag" width="650px">
      <div class="left2right">
        <span class="left">{{$t('public.userPhone')}}:  </span>
        <span class="right">{{tel}}</span>
      </div>
      <div class="left2right">
        <span class="left">{{$t('public.submitDate')}}:  </span>
        <span class="right">{{time}}</span>
      </div>
      <div class="left2right">
        <span class="left">{{$t('userSuggest.suggest')}}:  </span>
        <div class="right">
          <el-input type="textarea" :rows="4" v-model="sugCon" disabled maxlength="600"></el-input>
        </div>
      </div>
      <div class="left2right">
        <span class="left"></span>
        <div class="right">
          <el-image :src="feedbackPictureUrl" :preview-src-list=[feedbackPictureUrl] v-if="feedbackPictureUrl"></el-image>
        </div>
      </div>
      <div class="left2right">
        <span class="left">{{$t('userSuggest.sugReply')}}:  </span>
        <div class="right">
          <el-input type="textarea" :rows="4" v-model="replyContent" disabled maxlength="600"></el-input>
        </div>
      </div>
    </el-dialog>
    <!-- ------------------ 点击查看详情弹窗结束 -------------------- -->

    <!-- ------------------ 点击回复弹窗开始 -------------------- -->
    <el-dialog :title="$t('userSuggest.title2')" :visible.sync="replyFlag" width="650px">
      <div class="reply-main">
        <div class="reply-main-con">
          <div class="reply-con-one">
            <div class="reply-con-one-1">
              {{$t('public.userPhone')}}:
            </div>
            <div class="reply-con-one-2">
              {{tel}}
            </div>
          </div>
          <div class="reply-con-one">
            <div class="reply-con-one-4">
              {{$t('userSuggest.suggest')}}:
            </div>
            <div class="reply-con-one-5">
              <textarea class="search_input" v-model="sugCon" disabled maxlength="600"></textarea>
              <el-image :src="feedbackPictureUrl" :preview-src-list=[feedbackPictureUrl] v-if="feedbackPictureUrl"></el-image>
            </div>
          </div>
          <div class="reply-con-one">
            <div class="reply-con-one-4">
              {{$t('userSuggest.sugReply')}}:
            </div>
            <div class="reply-con-one-3">
              <textarea class="search_input" v-model="replyCon" :placeholder="$t('userSuggest.placeholder')+'~'" maxlength="600"></textarea>
            </div>
          </div>
          <div class="reply-but" @click="replySubmit">{{$t('userSuggest.sureSubmit')}}</div>
        </div>
      </div>
    </el-dialog>
    <!-- ------------------ 点击回复弹窗结束 -------------------- -->

    <!-- ------------------ 点击批量处理弹窗开始 -------------------- -->
    <el-dialog :title="$t('userSuggest.all')" :visible.sync="allDataFlag" width="750px">
      <el-table :data="multipleSelection" size="small" stripe style="width: 100%">
        <el-table-column align="center" prop="user.phone" :label="$t('public.registerPhone')" width="120">
        </el-table-column>
        <el-table-column align="center" prop="content" :label="$t('userSuggest.suggest')" :show-overflow-tooltip="true" min-width="200">
        </el-table-column>
        <el-table-column align="center" prop="createTime" :label="$t('public.submitDate')" width="140">
        </el-table-column>
      </el-table>
      <div class="left2right mt15">
        <span class="left">{{$t('userSuggest.suggest')}}:  </span>
        <div class="right">
          <el-select size="small" v-model="allData_status" :placeholder="$t('public.placeholder')">
            <el-option v-for="item in options" :key="item.value" :label="$t(item.label)" :value="item.value">
            </el-option>
          </el-select>
        </div>
      </div>
      <div class="left2right">
        <span class="left">{{$t('public.no37')}}:  </span>
        <div class="right">
          <el-input type="textarea" :rows="4" v-model="remark" maxlength="600"></el-input>
        </div>
      </div>
      <div class="left2right">
        <span class="left"></span>
        <div class="right">
          <el-button type="primary" size="small" @click="allDataSubmit">{{$t('proManage.sure')}}</el-button>
        </div>
      </div>
    </el-dialog>
    <!-- ------------------ 点击批量处理弹窗结束 -------------------- -->

    <div class="foot"></div>

  </div>
</template>
<script>
import getApp from 'src/mixins/getApp.js';//app和apk下拉搜索
import putExcel from 'src/mixins/putExcel.js';//导出excel
import getMerchant from 'src/mixins/getMerchant.js';//商户名称下拉
export default{
  mixins:[ getApp,putExcel,getMerchant],
  data () {
    const searchData=[
      {
        type: 'input',
        label: 'public.userPhone',
        attr: 'phone',
        value: ''
      },{
        type: 'rangePicker',
        label: 'public.submitDate',
        attr: 'searchTime',
        value: [],
      },{
        type: 'select',
        attr: 'status',
        label: 'public.no22',
        option: this.$store.state.options.suggest_option,
        value: '',
        langFlag: true,
      },{
        type: 'select',
        attr: 'appName',
        label: 'public.appName',
        option: [],
        value: '',
        langFlag: false,
      },{
        type: 'select',
        attr: 'appPackage',
        label: 'public.appPackage',
        option: [],
        value: '',
        langFlag: false,
      },this.$route.name=='usersugs'?{
        type: 'select',
        attr: 'regDevice',
        label: 'add.no7',
        option: this.$store.state.options.loanDevice_options, // 借款客户端,
        value: '',
        langFlag: true,
      }:'',
      this.$route.name=='usersugs'?{
        type: 'select',
        attr: 'partnerId',
        label: 'proManage.partnerName',
        option: [], //商户名称
        value: '',
        langFlag: false,
      }:'',
    ]
    return {
      routeName:this.$route.name,
      flag: true,
      pagination: {
        pageSize: global.config.pageSize,
        pageSizeOptions: global.config.pageSizeOptions,
        current: 1,
        total: 0,
      },
      searchData:searchData,
      putExcelUrl:this.$action.user_userSugExcel,
      formInline: {// 点击查询按钮对应数据
        status: '',
        phone: '',
        createTimeBegin: '',
        createTimeEnd: '',
        appName:'',
        appPackage:''
      },
      options: this.$store.state.options.suggest_option_allData, // 下拉选框信息
      tableData: [], // 用户信息数据模拟
      replyFlag: false, // 回复弹窗开关
      detailFlag: false, // 详情弹窗开关
      allFlag: false, // 批量处理展示与否
      replyId: '', // 选择的是当前回复行的ID
      time: '', // 点击详情需要传递的时间数据
      tel: '', // 点击详情需要传递的电话号码数据
      replyCon: '', // 回复的内容
      sugCon: '', // 用户建议
      replyContent: '', // 查看详情回复的内容展示
      feedbackPictureUrl: '', // 查看详情回复的图片展示
      multipleSelection: [], // 可勾选表格选中项
      allDataFlag: false, // 可勾选表格选中项
      allData_status: '', // 批量提交状态值
      remark: '',// 批量提交备注
    }
  },
  methods: {
    sugDetail (row) { // 点击查看详情
      this.detailFlag = true;
      this.tel = row.user.phone;
      this.time = row.replyTime;
      this.sugCon = row.content;
      this.replyContent = row.replyContent;
      this.feedbackPictureUrl = row.pictureUrl;
    },
    handleSizeChange (val) {// 每页条数变化时操作
      this.pagination.pageSize = val;
      this.sugList();
    },
    handleCurrentChange (val) { // 分页按钮点击操作
      this.pagination.current = val;
      this.sugList();
    },
    reply (row) { // 回复按钮操作
      this.replyFlag = true;
      this.replyId = row.id;
      this.tel = row.user.phone;
      this.sugCon = row.content;
      this.replyCon = row.replyContent;
      this.feedbackPictureUrl = row.pictureUrl;
    },
    replySubmit () { // 回复确认要做的事情
      if (this.flag) {
        this.flag = false;
        let arr=[];
        arr.push(this.replyId);
        if (this.replyCon) {
          let option = {
            param: {
              ids: arr,
              status: 3,
              replyContent: this.replyCon
            }       
          }
          this.$axios.post(this.$action.user_userSugReply, option).then(res => {
            this.flag = true;
            if (res.code == 200) {
              this.$globalMsg.success(this.$t('userSuggest.success'));
              this.sugList();
            } else {
              this.$globalMsg.err(this.$t('userSuggest.err'));
            }
            this.replyFlag = false;
          })
        } else {
          this.$globalMsg.error(this.$t('userSuggest.replyFirst'));
          this.flag = true;
        }
      }
    },
    search(search) { // 点击查询按钮
      this.formInline = {
        partnerId:search.partnerId,
        phone:search.phone,
        createTimeBegin:search.searchTime?search.searchTime[0]:'',
        createTimeEnd:search.searchTime?search.searchTime[1]:'',
        status:search.status,
        appName:search.appName,
        appPackage:search.appPackage
      };
      if (this.flag) {
        this.pagination.currentPage = 1;
        this.flag = false;
        this.sugList();
      }
    },
    sugList () { // 获取用户反馈列表
      let option = {
        pageNum:this.pagination.current,
        pageSize:this.pagination.pageSize,
        param: {
          ...this.formInline
        }       
      }
      this.$axios.post(this.$action.user_userSuglist, option).then(res => {
        this.flag = true;
        if (res.code == 200) {
          this.tableData = res.data.list;
          this.pagination.total = res.data.total;
          if (this.formInline.phone !== '') {
            this.allFlag = true;
          } else {
            this.allFlag = false;
          }
        }else{
          this.$globalMsg.error(res.message)
        }
      })
    },
    unSelect (row) {
      return !!(row.status == 1 || row.status == 2);
    },
    allDataDispose () { // 批量处理弹窗开关
      if(this.allFlag){
        if (this.multipleSelection == '') {
          this.$globalMsg.error(this.$t('loanAfterManage.selFirst'));
        } else {
          this.allDataFlag = true;
        }
      }  
    },
    handleSelectionChange (val) { // 表格选中项数据
      this.multipleSelection = val;
    },
    allDataSubmit () { // 批量处理确认操作
      if (this.remark == '') {
        this.$globalMsg.error(this.$t('userSuggest.placeholder'));
        return;
      }
      let arr = [];
      this.multipleSelection.forEach(value => {
        arr.push(Number(value.id));
      })
      if (this.flag) {
        this.flag = false;
        let option = {
            param: {
              replyContent: this.remark,
              status: 3,
              ids: arr
            }       
          }
        this.$axios.post(this.$action.user_userSugReply, option).then(res => {
          this.flag = true;
          this.allFlag = false;
          if (res.code == 200) {
            this.$globalMsg.success(this.$t('userSuggest.success'));
          } else {
            this.$globalMsg.error(res.header.msg);
          }
          this.allDataFlagClose();
          this.sugList();
        })
      }
    },
    allDataFlagClose () {
      this.remark = '';
      this.allDataFlag = false;
    },
    detailClose () {
      this.detailFlag = false;
      this.feedbackPictureUrl = '';
    },
    replyClose () {
      this.replyFlag = false;
      this.feedbackPictureUrl = '';
    }
  },
  mounted () {
    this.getApp().then(app=>{
      this.searchData[3].option=app.appName;
      this.searchData[4].option=app.appPackage;
    })
    if(this.routeName=='usersugs'){
      this.getMerchant().then(arr=>{
        this.searchData[6].option=arr;
      })
    }
    this.sugList();// 获取用户反馈列表
  }
}
</script>
<style scoped lang="scss">
.reply-main{
  width: 100%;
  .reply-main-con{
    width: 100%;
    height: auto;
    padding: 10px 0;
    .reply-con-one{
      width: 100%;
      display: flex;
      .reply-con-one-1{
        width: 100px;
        height: 40px;
        text-align: center;
        line-height: 40px;
        color: #999;
      }
      .reply-con-one-2{
        width: 560px;
        height: 40px;
        line-height: 40px;
      }
      .reply-con-one-3{
        width: 560px;
        height: 100%;
        margin-bottom: 10px;
        textarea{
          width: 100%;
          height: 100px;
          font-size: 16px;
          padding: 5px;
        }
      }
      .reply-con-one-5{
        width: 560px;
        height: 100px;
        display: flex;
        justify-content: space-between;
        margin-bottom: 10px;
        textarea{
          width: 70%;
          height: 100px;
          font-size: 16px;
          padding: 5px;
        }
        .imgbox{
          width: 24%;
          height: 100px;
        }
      }
      .reply-con-one-4{
        width: 100px;
        height: 40px;
        text-align: center;
        color: #999;
      }
    }
    .reply-con-two{
      width: 100%;
      height: 100px;
      margin-bottom: 22px;
      textarea{
        width: 100%;
        height: 100%;
        padding: 10px;
        font-size: 16px;
        background-color: #f4f6fb;
        color: #000;
      }
    }
    .reply-but{
      width: 220px;
      height: 38px;
      background-color: #547ef5;
      border-radius: 5px;
      margin: 10px auto;
      text-align: center;
      line-height: 38px;
      font-size: 16px;
      color: #fff;
      cursor: pointer;
    }
  }
}

.detail_pic{
  width: 200px;
}

</style>
